﻿using DLog.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication
{
    public partial class Index : System.Web.UI.Page
    {
        DLog.ILogger logger;
        protected void Page_Load(object sender, EventArgs e)
        {
            logger = DLog.SyncLogManager.GetCurrentClassLogger();
            if (!IsPostBack)
            {
                logger.Trace("Trace test information");
                logger.Debug("debug test information");
                logger.Info("info test information");
                logger.Warn("Warn test information");
                logger.Error("Error test information");
                logger.Fatal("Fatal test information");
                //GvDataBind();
                Response.Write("Index load successfully！");
            }
        }

        protected void btnLog_Click(object sender, EventArgs e)
        {
            logger.Debug(new Exception("record exception infomation"));
            logger.Info("you click button at " + DateTime.Now.ToString());
            GvDataBind();

            
        }

        public void GvDataBind()
        {
            int totalCount;
            List<LogModel> logList = logger.GetLogs( 2, 8, out totalCount);
            gvLogs.DataSource = logList;
            gvLogs.DataBind();
        }

        protected void gvLogs_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvLogs.PageIndex = e.NewPageIndex;
            GvDataBind();
        }
    }
}